package cn.webrx.calendarexample;


import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Ex4 {
    public static void main(String[] args) throws ParseException {
        String time = "2023-10-11 2:05:00";
        String msg = "你好，在吗？";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long ti = sdf.parse(time).getTime();
        long nn = System.currentTimeMillis();

        if ((nn - ti) / 1000 / 60 < 1) { //<1分钟
            System.out.printf("刚刚：%s%n", msg);
        }

        long t1 = (nn - ti) / 1000 / 60;
        if (t1 >= 1 && t1 < 60) { //>1分钟 < 60分钟
            System.out.printf("%d分钟前：%s%n", t1, msg);
        }

        long t2 = (nn - ti) / 1000 / 60 / 60;
        if (t2 >= 1 && t2 < 24) {//小时
            System.out.printf("%d小时前：%s%n", t2, msg);
        }

        long t3 = (nn - ti) / 1000 / 60 / 60 / 24;
        if (t3 >= 1 && t3 <= 7) {
            System.out.printf("%d天前：%s%n", t3, msg);
        } else if (t3 > 7) {
            System.out.printf("%tF %<tT：%s%n", ti, msg);
        }
    }
}
